import { Component, OnInit } from '@angular/core';
import { DatePipe } from '@angular/common'

declare var form: any;

@Component({
  templateUrl: './special.report.component.html',
  providers: [DatePipe]
})



export class SpecialReportComponent implements OnInit {
  fs: any = null;
  // 字典

  public dicTypeDic: any = null;

  public reportDic: any = null;

  public monthDic: any = null;

  constructor(private datePipe: DatePipe) {
    // 注册表单
    this.fs = new form.FormTreeService('specialreport', {
      orderObject: { order: 0 },
      keyField: 'id',
      randomFields: ['id'],
      pageSize: 1000,
      defaultObject: { leaf: false }
    });
    this.fs.loadData(true);
    
    this.dicTypeDic = new form.DictionaryService('report_type');
    this.reportDic = new form.DictionaryService('report_dictionary');
    this.monthDic = new form.DictionaryService('report_month');
  }


  ngOnInit() {
  }

  //date改string
  yearChange(val,num){
    let myYear = this.datePipe.transform(val,"yyyy");
    // console.log(myYear)
    if(num == 1){
      this.fs.queryObject.year = myYear
    }else if(num == 2){
      this.fs.er.year = myYear
    }
  }

  saveForm() {
    this.yearChange(this.fs.er.reportYear,2)
    if ( this.fs.er.reporttype == '1') {
      this.fs.er.leaf = 1;
    } else {
      this.fs.er.leaf = 0;
    }
    if(this.fs.er.reporttype == '0'){
      this.fs.er.year = null
      this.fs.er.reportYear = null
      this.fs.er.month = null
      this.fs.er.tablename = null
    }
    this.fs.save();
  }
  
  editReport(item){
    if (item.year != null){
      let myDate = item.year+"/1/1"
      item.reportYear = new Date(myDate)
    }
    // console.log(item.year)
    this.fs.editRow(item)
  }

}
